package znbkMain;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.widget.Toast;

import com.example.lancooznbk.R;
import com.example.lancooznbk.utils.ActivityUtil;
import com.example.lancooznbk.view.base.BaseActivity;

import znbkFragment.ZnbkMainFragment;

/**
 * Created by Administrator on 2018\2\6 0006.
 */

public class ZnbkMainMenuActivity extends BaseActivity {
    @Override
    public int attachLayoutRes() {
        return R.layout.hyznbk_activity_to_fragment_main;
    }

    @Override
    protected void initViews() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.add(R.id.fl_container,new ZnbkMainFragment());
        transaction.commit();
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    //按两次退出应用
    private long mExitTime;
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {

            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                if ((System.currentTimeMillis() - mExitTime) > 2000) {
                    Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
                    mExitTime = System.currentTimeMillis();
                } else {
                    ActivityUtil.getInstance().AppExit();
                }
            }


            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
